(function(app){
	app
		.controller("content_08_inputCtrl",["$scope","$state","myFactory","$http","$stateParams","$state","$q","$ionicHistory","$timeout",function($scope,$state,myFactory,$http,$stateParams,$state,$q,$ionicHistory,$timeout){
			
			//接收参数
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var searchParam = $stateParams.searchParam;
			var policyData;//保单详情
			var itemData;//用于接收初始化查询initContentItem的内容，里面存在各种各样的内容，比如item02_1
			var systemDate;//系统时间，从后台已经封装上来了
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var token=sessionStorage.getItem("token");
			//绑定参数到页面
			$scope.chdrnum01 = $stateParams.chdrnum01;
			$scope.NewPopSexFlag = false;//增加弹框性别控制按钮，默认为false，也即默认选定男
			$scope.EditPopSexFlag = false;
			
			$scope.isPhotoOCRFlag=true;
			
			//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
			$scope.isChangeIdNum0 = false;//正面
			$scope.isChangeIdNum1 = false;//反面
			var cache = "";
			/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 start*/
			$scope.readFlag = false;//阅读协议标志，默认为false
			/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 end*/

			//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
			
			//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start
			$scope.openWindow = "";
			//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end
			//
			//先初始化
			$scope.item08 = {
				"benefit" : []
			}
/***************************************************************初始化部分begin****************************************************/
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						itemData = response.data.data.modelMap;
						systemDate = itemData.systemDate;
						if(itemData.item08 !=null && itemData.item08 !=undefined && itemData.item08!= ""){
							$scope.item08 = itemData.item08;
						}
						var nation = itemData.nationabdc;
						$scope.nationObj =  eval("("+nation+")");
						initFlag=true;//标识初始化成功
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				myFactory.initDateUtil('availDataStartNew',"");
				myFactory.initDateUtil('availDataStartEdit',"");
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end

				//初始化有效截止日期
				myFactory.initDateUtil('availDataCloseNew',"");
				myFactory.initDateUtil('availDataCloseEdit',"");
				//初始化出生日期
				myFactory.initDateUtil('birthDayNew',"");
				myFactory.initDateUtil('birthDayEdit',"");
			}
/***************************************************************初始化部分end****************************************************/
			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//返回函数
			$scope.goBack = function () {
				myFactory.goBack();
			}
			//保单详情弹框
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn08Input','overwindowOn08Input','policyCloseXOn08Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化时候查询保单详情
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;//绑定至页面
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}
			//保单详情弹窗关闭函数
			$scope.policyCancelOn08Input = function(){
				modal('close','policyModalOn08Input','overwindowOn08Input','policyCloseXOn08Input');
			}
//			//关闭遮罩,考虑人性化，这里不开放点遮罩时候关闭
//			$scope.overwindowClose = function(){
//				//$(".overwindow").show();
//				$(".overwindow").hide();
//				$(".overmodal").hide();
//			}

/*******************************************************公共校验部分begin********************************************************/	
			
			/**
			 * 证件校验部分
			 */
			//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 update by huanghk 20231115 start
			var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",
			        21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",
			        33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",
			        42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",
			        51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",
			        63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门" //,91:"国外"
			};
			//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 update by huanghk 20231115 end
			//检查号码是否符合规范，包括长度，类型
			function isCardNo(card){
				//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
				//var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/; //ZZQ:原代码进行了注释，这意味着15位不再使用
				var reg = /(^\d{17}(\d|[Xx])$)/;
				if(reg.test(card) == false){
					return false;
				}
				return true;
			};		
			
			function checkProvince(card){//取身份证前两位,校验省份
				var province = card.substr(0,2);
				if(vcity[province] == undefined){
					return false;
				}
				return true;
			};
			
			checkBirthday = function(card){//检查生日是否正确
				var len = card.length;
				if(len == '15'){//身份证15位时，次序为省（3位）市（3位）年（2位）月（2位）日（2位）校验位（3位），皆为数字
				    var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/; 
				    var arr_data = card.match(re_fifteen);
				    var year = arr_data[2];
				    var month = arr_data[3];
				    var day = arr_data[4];
				    var birthday = new Date('19'+year+'/'+month+'/'+day);
				    return verifyBirthday('19'+year,month,day,birthday);
				}

				if(len == '18'){//身份证18位时，次序为省（3位）市（3位）年（4位）月（2位）日（2位）校验位（4位），校验位末尾可能为X
				    var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|[Xx])$/;
				    var arr_data = card.match(re_eighteen);
				    var year = arr_data[2];
				    var month = arr_data[3];
				    var day = arr_data[4];
				    var birthday = new Date(year+'/'+month+'/'+day);
				    return verifyBirthday(year,month,day,birthday);
				}
				return false;
			};
			
			function verifyBirthday(year,month,day,birthday){//校验日期
				var now = new Date();
				var now_year = now.getFullYear();

				if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day){//年月日是否合理
					
					/*var time = now_year - year;
					if(time >= 3 && time <= 100){//判断年份的范围（3岁到100岁之间)
						return true;
					}
					return false;
					*/
					return true;
				}
				return false;
			};


			function checkParity(card){//校验位的检测
				//15位转18位 
				//card = changeFivteenToEighteen(card);    ZZQ:不再采用15位，所以不需要
				var len = card.length;
				if(len == '18'){
				    var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
				    var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
				    var cardTemp = 0, i, valnum; 
				    for(i = 0; i < 17; i ++){
				        cardTemp += parseInt(card.substr(i, 1)) * arrInt[i];
				    }
				    valnum = arrCh[cardTemp % 11];
				    if (valnum == card.substr(17, 1).toUpperCase()){
				        return true;
				    }
				    return false;
				}
				return false;
			};

			//15位转18位身份证号
			function changeFivteenToEighteen(card){
				if(card.length == '15'){
				    var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
				    var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
				    var cardTemp = 0, i;   
				    card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
				    for(i = 0; i < 17; i ++) 
				    { 
				        cardTemp += card.substr(i, 1) * arrInt[i]; 
				    } 
				    card += arrCh[cardTemp % 11]; 
				    return card;
				}
				return card;
			};
			
			/*根据出生日期算出年龄*/  
			function getAge(strBirthday){         
				var returnAge;  
				var strBirthdayArr=strBirthday.split("-");  
				var birthYear = strBirthdayArr[0];  
				var birthMonth = strBirthdayArr[1];  
				var birthDay = strBirthdayArr[2];  
				
				d = new Date();  
				var nowYear = d.getFullYear();  
				var nowMonth = d.getMonth() + 1;  
				var nowDay = d.getDate();  
				
				if(nowYear == birthYear){  
					returnAge = 0;//同年 则为0岁  
				} else {  
					var ageDiff = nowYear - birthYear ; //年之差  
					if(ageDiff > 0){  
						if(nowMonth == birthMonth) {  
							var dayDiff = nowDay - birthDay;//日之差  
							if(dayDiff < 0) {  
								returnAge = ageDiff - 1;  
							} else {  
								returnAge = ageDiff ;  
							}  
						} else {  
							var monthDiff = nowMonth - birthMonth;//月之差  
							if(monthDiff < 0) {  
								returnAge = ageDiff - 1;  
							} else {  
								returnAge = ageDiff ;  
							}  
						}  
					} else {  
						returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天  
					}  
				}  
				return returnAge;//返回周岁年龄  
			}  
			
			//对外开放函数，调用这个即可
			function checkCard(card){
				if(isCardNo(card) == false){//校验长度，类型
					return "身份证号码不正确或非18位";
				}

				if(checkProvince(card) == false){//检查省份
				    return "身份证号码不正确";
				}

				if(checkBirthday(card) == false){//校验生日
				    return '身份证号码生日不正确';
				}

				if(checkParity(card) == false){//检验位的检测
				    return "您的身份证校验位不正确,请重新输入";
				}
				return "";
			};
			
			//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
			//外国人永久居留身份证校验
			function checkCardToA(card,birthday,sex){
				var len = card.length;
				if(len!=15 && len!=18){//校验长度
					return false;
				}
				var letterReg = /^[a-zA-Z]{3}\d{12}$/;
				var numberReg = /^[0-9]*$/;
				if(len==15){
					if (!letterReg.test(card)) {
						return false;
					}
				}
				if(len==18){
					var num1 = card.substring(0, 1);//第1位，必须为9开头
					var num7 = card.substring(6, 14);//第7-14位，判断出生日期
					var num17 = card.substring(16, 17);//第17位，判断性别
				    if (!numberReg.test(card) || num1!="9") {
						return false;
					}
				    birthday = birthday.replaceAll('-', '');
					if(birthday!=num7){
						return false;
					}
					if((num17%2)==0){
						//偶数--女性
						if(sex!="F"){
							return false;
						}
					}else{
						//奇数--男性
						if(sex!="M"){
							return false;
						}
					}
				}
				return true;
			};
			
			function changeAvailDataStart(dataStart,dataEnd,birthDay){
				dataStart = dataStart.replaceAll('-', '');
				dataEnd=dataEnd.replaceAll('-', '');
				birthDay=birthDay.replaceAll('-', '');
				//计算年龄（有效期起始日-出生日期）
				var age = getTimeDifference(dataStart,birthDay);
				
				//截止日+1天
				var dataEndT = new Date(dataEnd.substring(0,4)+'/'+dataEnd.substring(4,6)+'/'+dataEnd.substring(6,8));
				dataEndT = new Date(dataEndT.getTime() + 24*60*60*1000);
				var endYear = dataEndT.getFullYear();
				var endMonth = dataEndT.getMonth() + 1;  
				var endDay = dataEndT.getDate();
				endMonth = endMonth < 10 ? '0' + endMonth : endMonth;
	            endDay = endDay < 10 ? '0' + endDay : endDay;
				var endMD = endMonth.toString() + endDay.toString();
				var dataEndDateTStr = endYear.toString() + endMD;
				var period = getTimeDifference(dataEndDateTStr,dataStart);
				
				if(age<18){
					if(period!=5){
						return false;
					}
				}else{
					if(period!=10){
						return false;
					}
				}

				var dataStartMD = dataStart.substring(4,8);
				var dataEndMD = dataEnd.substring(4,8);
				if(dataStartMD!="0229" && dataEndMD!="0229"){		
					if(dataStartMD!=dataEndMD && dataStartMD!=endMD){
						return false;
					}				
				}
				return true;
			}

			
			function getTimeDifference(dataStart,dataEnd){         
				var returnYear;  
				
				var dataStart = dataStart.replaceAll('-', '');
				var dataStartYear = dataStart.substring(0,4); 
				var dataStartMonth = dataStart.substring(4,6);   
				var dataStartDay = dataStart.substring(6,8); 
				
				var dataEnd=dataEnd.replaceAll('-', '');
				var dataEndYear = dataEnd.substring(0,4); 
				var dataEndMonth = dataEnd.substring(4,6);
				var dataEndDay = dataEnd.substring(6,8);
				
				if(dataStartYear == dataEndYear){  
					returnYear = 0;//同年
				} else {  
					var yearDiff = dataStartYear - dataEndYear ; //年之差  
					if(yearDiff > 0){  
						if(dataStartMonth == dataEndMonth) {  
							var dayDiff = dataStartDay - dataEndDay;//日之差  
							if(dayDiff < 0) {  
								returnYear = yearDiff - 1;  
							} else {  
								returnYear = yearDiff ;  
							}  
						} else {  
							var monthDiff = dataStartMonth - dataEndMonth;//月之差  
							if(monthDiff < 0) {  
								returnYear = yearDiff - 1;  
							} else {  
								returnYear = yearDiff ;  
							}  
						}  
					} else {  
						returnYear = -1;//返回-1 表示日期输入错误
					}  
				}  
				return returnYear;
			}

    		String.prototype.replaceAll = function(s1, s2) {
    			return this.replace(new RegExp(s1, "gm"), s2);
    		}
    		//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
			
			
			// 出生日期不能大于当前日期
			function birthDayContrast(type){
				var a = $("#birthDay"+type).val(); //出生日期
				var newdateb=new Date();
				newdateb.setMonth(newdateb.getMonth()-1);
			    var is11=newdateb.getFullYear()+"-"+(newdateb.getMonth()+1)+"-"+newdateb.getDate();
			    if(a>is11){
			    	myFactory.alert("","出生日期不能大于当前日期，请确认后填写！","info");
			    }
			}
			
			//检查日期性别是否与身份证号匹配
			//一个调用例子checkDateOrSex("New",$scope.NewPopSexFlag)
			function checkDateOrSex(type,sexFlag){  //其中，type会传入比如New或者_1这样的，而sexId会传过来像$scope.NewPopSexFlag
				//身份证号
				var iIdNo = $("#idNo"+type).val();
				//性别
				var iSex;
				if(sexFlag == false){
					iSex = "M";
				}else{
					iSex = "F";
				}
				//出身年月日
				var iDate=$("#birthDay"+type).val();
				
				if((iIdNo!=""||iIdNo!=null)&&(iIdNo.length == 15) || (iIdNo.length == 18)){
					//身份证号包含的出生年月日
					var iIdDate="";
					if (iIdNo.length == 15) {
						iIdDate = iIdNo.substring(6, 12);
						iIdDate = "19" + iIdDate;
						iIdDate = iIdDate.substring(0, 4) + "-" + iIdDate.substring(4, 6) + "-" + iIdDate.substring(6)
					}
					else {
						iIdDate = iIdNo.substring(6, 14);
						iIdDate = iIdDate.substring(0, 4) + "-" + iIdDate.substring(4, 6) + "-" + iIdDate.substring(6)
					}
					
					var test=iIdNo.substr(iIdNo.length-2,1);
				
					if(test%2!=0){
						test="M";
					}
					if(test%2==0){
						test="F";
					}
					if(test!=iSex){
						myFactory.alert("","证件号码与性别不匹配，请重新确认 ！","info");
						return false;
					}
					else if(iDate!=iIdDate){
						myFactory.alert("","证件号码与出生日期不匹配，请重新确认！ ","info");
						return false;
					}
				} else{
					myFactory.alert("","证件号码错误，请重新确认！  ","info");
					return false;
				}
				return true;
			}
			
			/**
			 * 只输入整数函授
			 */
			$scope.keyNumPress = function(){
				var keyCode = event.keyCode;
				if(keyCode>=48 && keyCode<=57){
					event.returnValue = true;
				}else{
					event.returnValue = false;
				}
			}
			
			//证件号码失去焦点时候触发校验函数
			$scope.idNoblur = function(type){ //type为New 或者 edit
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
			//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				$timeout(function(){
					if ( type == 'Edit1' && cache != $('#availDataCloseEdit').val() ){
						$scope.isChangeIdNum1 = true;
					}
					if ( type == 'New1' && cache != $('#availDataCloseNew').val() ){
						$scope.isChangeIdNum1 = true;
					}
					if ( type == 'Edit0' && cache != $('#idNoEdit').val() ){
						 $scope.isChangeIdNum0 = true;
					}
					if ( type == 'New0' && cache != $('#idNoNew').val() ){
						 $scope.isChangeIdNum0 = true;
					}
				
						type = type.substring(0,type.length-1)
					
					//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
					//S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
					$("#idNo"+type).val(document.getElementById("idNo"+type).val().toUpperCase());
					//S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
					var idNo = $("#idNo"+type).val();//所输入的证件号码
					var idType = $("#idType"+type+"Select").val();//证件类型
					if(idType =='1' || idType =='7' ){
						var checkStr = checkCard(idNo);
						//先执行对证件号码的校验，如果没有错再进入下一步设置出声日期以及性别
						if(checkStr!=""){
							myFactory.alert("",checkStr,"info");
							return false;
						}else{
							var id_birth = idNo.substring(6,14);
							/*截取年份*/
							var id_year = id_birth.substring(0,4);
							/*截取月份*/
							var id_month = id_birth.substring(4,6);
					 		/*截取天数*/
					 		var id_day = id_birth.substring(6,8);
						 	var _birthday = id_year+"-"+id_month+"-"+id_day;
						 	//设置出生年月
						 	$("#birthDay"+type).val(_birthday);
						 	
						 	var is_fandm = idNo.substring(16,17);
						 	//设置性别
						 	if(is_fandm%2==1){
						 		//$scope.addPopSexFlag = false;
						 		$scope[type+"PopSexFlag"] = false;
						 	}else if(is_fandm%2==0){
						 		//$scope.addPopSexFlag = true;
						 		$scope[type+"PopSexFlag"] = true;
						 	}
						 	return true;
						}
					}else{
						return true;
					}
					},1500);
			}
			
			//国籍触发函数
			$scope.changenativePlaceText = function(type){
				var options = "";
				options =$("#nativePlaceText"+type+"Select option:selected");
				console.log(options.text());
				console.log(options.val());
				$("#nativePlaceText"+type+"Input").val(options.text());
				$("#nativePlaceNm"+type).val(options.text());
				$("#nativePlace"+type).val(options.val());
			}
			
			//证件类型变动时触发函数
			$scope.changeIdType = function(type){
				//首先先将选中值体现出来
				var options = "";
				var idType = $("#idType"+type+"Select").val();//证件类型
				options =$("#idType"+type+"Select option:selected");
				console.log(options.text());
				console.log(options.val());
				$("#idType"+type+"Input").val(options.text());

				//如果是身份证，则强行让国籍为中国，并且变为不可改变
				if(idType=='1'){
					$("#nativePlaceText"+type+"Input").val("中国 China");
					$("#nativePlaceNm"+type).val("中国 China");
					$("#nativePlace"+type).val("CHN");
					$("#nativePlaceText"+type+"Select").val("CHN"); //选择国籍为中国
					$("#nativePlaceText"+type+"Select").attr("disabled",true); //禁止二次选择
				}else{
					$("#nativePlaceText"+type+"Select").attr("disabled",false);
					$("#nativePlaceText"+type+"Select").val("CHN"); //保留国籍为中国
				}
				
				//如果是外国人永久居留身份证，则有限期只能为终生
//				if(idType=='A'){ 
//					$("#availDataType"+type+"Input").val("终生");
//					$("#availDataType"+type+"Select").val("2");
//					$("#availDataType"+type+"Select").attr("disabled",true); //禁止二次选择
//				}else{
//					$("#availDataType"+type+"Select").attr("disabled",false); //禁止二次选择
//				}
			}
			//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
			//证件有效期以及证件号码修改触发函数
//			$scope.changeInpuData = function(type){
//				if ( cache ) return;
//				if ( type == 'Edit1' && cache != $('#availDataCloseEdit').val() ){
//					$scope.isChangeIdNum1 = true;
//				}
//				if ( type == 'New1' && cache != $('#availDataCloseNew').val() ){
//					$scope.isChangeIdNum1 = true;
//				}
//				if ( type == 'Edit0' && cache != $('#idNoEdit').val() ){
//					 $scope.isChangeIdNum0 = true;
//				}
//				if ( type == 'New0' && cache != $('#idNoNew').val() ){
//					 $scope.isChangeIdNum0 = true;
//				}
//			}
//			$scope.onDateCloseBlur=function(type){
////				myFactory.alert("","失去焦点","info");
////				cache ="";
//				if ( cache ) return;
//				
//			}
			$scope.onInputFocus = function(type){
				//myFactory.alert("","获得焦点","info");
				if ( type == 'Edit1' ) {
					cache= $('#availDataCloseEdit').val();
				}
				if ( type == 'New1'  ){
					cache= $('#availDataCloseNew').val();
				}
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				if ( type == 'Edit1' ) {
					cache= $('#availDataStartEdit').val();
				}
				if ( type == 'New1'  ){
					cache= $('#availDataStartNew').val();
				}
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				if ( type == 'Edit0'  ){
					cache= $('#idNoEdit').val();
				}
				if ( type == 'New0'  ){
					cache= $('#idNoNew').val();
				}
				//	myFactory.alert("测试弹框","获得焦点，缓存的值是："+cache,"info");
			}
			//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
			// 证件有限期类型切换时触发函数
			$scope.changeAvailDataType = function(type){
				//首先先将选中值体现出来
				var options = "";
				var Datatype = $("#availDataType"+type+"Select").val();
				options =$("#availDataType"+type+"Select option:selected");
				console.log(options.text());
				console.log(options.val());
				$("#availDataType"+type+"Input").val(options.text());
				if(Datatype=='1' || Datatype=='3'){
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					$("#availDataStart"+type).val(" ");//置空有效期起始日，多一个空格，使不显示灰色提醒
					$("#availDataStart"+type).attr("disabled",false);
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					$("#availDataClose"+type).val(" ");//置空有效期截止日，多一个空格，使不显示灰色提醒
					$("#availDataClose"+type).attr("disabled",true);
				}else{
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					$("#availDataStart"+type).val("");//完全置空，使显示灰色提醒
					$("#availDataStart"+type).attr("disabled",false);
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					$("#availDataClose"+type).val("");//完全置空，使显示灰色提醒
					$("#availDataClose"+type).attr("disabled",false);
				}
			}
			
			//关系下拉框切换
			$scope.changeRelationToInsured = function(type){
				var options = "";
				options =$("#relationToInsured"+type+"Select option:selected");
				console.log(options.text());
				console.log(options.val());
				$("#relationToInsured"+type+"Input").val(options.text());
			}
			
			
/*******************************************************公公校验部分end********************************************************/	
			
/*******************************************************新增受益人部分begin***************************************************/
			//新增受益人弹窗 性别单选按钮样式控制
			$scope.newPopSex = function(type){
				if(type==1){
					$scope.NewPopSexFlag = false;
				}else if(type ==2){
					$scope.NewPopSexFlag = true;
				}
				console.log(type);
				console.log($scope.NewPopSexFlag);
			}
			
			//新增受益人
			$scope.addPeopleModelShow = function(){
				$.showLoading('正在处理,请稍候');
				setTimeout(function() {
					$.hideLoading();
				}, 300);
				
				modal('open','addPeopleModal','overwindowOn08Input','addPeopleModalCloseX');
				/**
				 * 数据初始化
				 */
				$("#nameNew").val("");
				//初始化证件选择，选择为身份证
				//$scope.idTypeNewSelect = "1";
				$scope.idTypeNewSelect = "";
				//$("#idTypeNewInput").val("身份证");
				$("#idTypeNewInput").val("");
				$("#idNoNew").val("");
				
				//强行让国籍为中国，并且变为不可改变
				/*$("#nativePlaceTextNewInput").val("中国 China");
				$("#nativePlaceNmNew").val("中国 China");
				$("#nativePlaceNew").val("CHN");
				$scope.nativePlaceTextNewSelect = "CHN";//选择国籍为中国
				$("#nativePlaceTextNewSelect").attr("disabled",true); //禁止二次选择*/
				$("#nativePlaceTextNewInput").val("");
				$("#nativePlaceNmNew").val("");
				$("#nativePlaceNew").val("");
				$scope.nativePlaceTextNewSelect = "";//选择国籍为中国
				
				//初始化有限期类型
				//$scope.availDataTypeNewSelect = "2";
				//$("#availDataTypeNewInput").val("年期");
				$scope.availDataTypeNewSelect = "";
				$("#availDataTypeNewInput").val("");
				//初始化性别
				$scope.NewPopSexFlag = false;
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				//初始化有效起始日
				$("#availDataStartNew").val("");
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				//初始化有效截止日
				$("#availDataCloseNew").val("");
				//初始化出生日期
				$("#birthDayNew").val("");
				//初始化关系
				//$scope.relationToInsuredNewSelect = "CH";
				//$("#relationToInsuredNewInput").val("子女");
				$scope.relationToInsuredNewSelect = "";
				$("#relationToInsuredNewInput").val("");
				//初始化受益顺序和受益比例
				$("#bnfGradeNew").val("");
				$("#bnfLotNew").val("");
				
				/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start*/
				$("#bnfMobileNew").val("");
				$("#bnfHomePhoneNew").val("");
				$("#bnfMobilexNew").val("");
				$("#bnfAddressNew").val("");
				/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end*/
			}
			//新增受益人关闭弹窗
			$scope.addPeopleCancel = function(){
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				$scope.isChangeIdNum0 = false;//正面
				$scope.isChangeIdNum1 = false;//反面
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				modal('close','addPeopleModal','overwindowOn08Input','addPeopleModalCloseX');
			}
			
			//确定添加新增受益人
			$scope.addPeopleComfirm = function(){
				/**
				 * 获取数据
				 */
				var name = $("#nameNew").val();//名字
				var nativePlace = $("#nativePlaceNew").val();//国籍代码
				var nativePlaceNm = $("#nativePlaceNmNew").val();//国籍名称
				var idType = $("#idTypeNewSelect option:selected").val();//证件类型代码
//				var idTypeCN = $("#idTypeNewSelect option:selected").text();//证件类型名称
				var idNo = $("#idNoNew").val();//证件号码
				var availDataType = $("#availDataTypeNewSelect option:selected").val();//有限期类型代码
//				var availDataTypeCN = $("#availDataTypeNewSelect option:selected").text();//有限期类型名称
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				var availDataStart = $("#availDataStartNew").val();//有效起始日
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				var availDataClose = $("#availDataCloseNew").val();//有效截止日
				var sex;
				if($scope.NewPopSexFlag == false){
					sex = "M";
				}else{
					sex = "F";
				}
				var birthDay = $("#birthDayNew").val();
				var relationToInsured = $("#relationToInsuredNewSelect option:selected").val();//关系代码
//				var relationToInsuredCN = $("#relationToInsuredNewSelect option:selected").text();//关系名称
				var bnfGrade = $("#bnfGradeNew").val();//受益顺序
				var bnfLot = $("#bnfLotNew").val();//受益比例
				
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
				var idCardBase64Img0 = $("#idCardBase64Img0New").val();//身份证正面
				var idCardBase64Img1 = $("#idCardBase64Img1New").val();//身份证反面
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
				
				/**
				 * 数据校验
				 */
				if(systemDate==null || systemDate == undefined || systemDate =="" ){
					myFactory.alert("","系统发生错误，请返回重试","info");
					return;
				}
				if(name == null || name.trim() == "" ){
					myFactory.alert("","名字不能为空","info");
					return;
				}
				if(nativePlace == null || nativePlace.trim() == "" || nativePlace == undefined){
					myFactory.alert("","请选择国籍","info");
					return;
				}
				if(idType == null || idType.trim() == "" || idType == undefined){
					myFactory.alert("","请选择证件类型","info");
					return;
				}
				
				//证件号码校验
				if(idType =='1' || idType =='7' ){
					var checkStr = checkCard(idNo);
					//先执行对证件号码的校验，如果没有错再进入下一步设置出声日期以及性别
					if(checkStr!=""){
						myFactory.alert("",checkStr,"info");
						return;
					}
				}
				
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(idType =='A'){
					if(!checkCardToA(idNo.trim(),birthDay.trim(),sex)){
						myFactory.alert("","证件号码不正确，请重新确认","info");
						return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
				if(idType =='A' && availDataType==1){
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 start
					myFactory.alert("","外国人永久居留身份证有效期类型不可选择长期","info");
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 end
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
					return;
				}
				
				if(idNo == null || idNo.trim() == ""){
					myFactory.alert("","证件号码不能为空","info");
					return;
				}
				
				if(availDataType == null || availDataType.trim() == "" || availDataType == undefined){
					myFactory.alert("","请选择有效期类型","info");
					return;
				}
				
				//当证件有效类型不是终身时执行校验
				if(availDataType!=1){
					if(availDataClose == null || availDataClose.trim() == ""){
						myFactory.alert("","有效截止日不能为空","info");
						return;
					}
					//证件有效期必须大于当前日期
				    if(availDataClose <= systemDate ){  	//需要注意的是，systemDate找不到定义所在
				    	myFactory.alert("","证件有效截止日必须大于当前日期，请重新确认","info");
				    	return;
				    }
				  //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				    if(availDataStart == null || availDataStart.trim() == ""){
						myFactory.alert("","有效起始日不能为空","info");
						return;
					}
				    if($.trim(availDataStart)<birthDay){ 
						prompt="有效期起始日必须大于出生日期，请确认后填写！";
						myFactory.alert('','有效期起始日必须大于出生日期，请确认后填写！','info');
						return false;
					}
				    if($("#idTypeNewInput").val() =="身份证"){
						if($.trim(availDataStart)<'2004-03-29'){
							prompt="有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！";
							myFactory.alert('','有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！','info');
							return false;
						}
				    }
					if($.trim(availDataStart)>systemDate){
						
						prompt="有效期起始日必须少于等于当前日，请确认后填写！";
						myFactory.alert('','有效期起始日必须少于等于当前日，请确认后填写！','info');
						return false;
					}
					
				  //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				}
				
				//出生日校验
				if(birthDay == null || birthDay.trim() == ""){
					myFactory.alert("","出生日期不能为空","info");
					return;
				}else{
					if( birthDay >= systemDate ){
						myFactory.alert("","出生日期不能大于当前日期，请重新确认","info");
				    	return;
				    }
				}
				
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(idType =='A'){
					if(!changeAvailDataStart(availDataStart,availDataClose,birthDay)){
						myFactory.alert("","您填写的证件有效期不正确，请按证件上的实际有效日期填写！","info");
				    	return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
				//证件类型为身份证时，45岁（含）以下证件有效期不可为终身
	   	   		if(idType == '1'){
	   	   			if(availDataType == '1'){
	   	   				var iDate=birthDay;//出生日期
						var age = getAge(iDate);
						if(age<=45){
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
							myFactory.alert("","45岁（含）以下有效期类型不可为长期，请重新确认","info");
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
   	   						return;
						}
	   	   			}
	   	   		}
				
		   	   	if(relationToInsured == null || relationToInsured.trim() == "" || relationToInsured == undefined){
					myFactory.alert("","请选择关系","info");
					return;
				}
				if(bnfGrade == null || bnfGrade.trim() == ""){
					myFactory.alert("","受益顺序不能为空","info");
					return;
				}
				if(bnfLot == null || bnfLot.trim() == ""){
					myFactory.alert("","比率不能为空","info");
					return;
				}
    	   		
				//重复校验身份证号码和性别、出生日期是否对应
				if(idType =='1' || idType =='7' ){
					var strReturn = checkDateOrSex("New",$scope.NewPopSexFlag);
					if(strReturn == false){
						return;    //如果返回false,说明校验失败
					}
				}
				
				// add by yinruirong 20180921 添加港澳台证件类型校验 start
				/**************************
				 * 1.证件类型为港澳台居民居住证(810000或820000或830000开头的18位数)，国籍只能选"中国-香港"、"中国-澳门"、"中国台湾"
				 * 2.证件有效期类型不能选择终身
				 * 3.证件有效期不能为空
				 */
				//S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
//				var re = /^\d{18}$/; //18位整数正则表达式
				var re = /^\d{18}$|^\d{17}X$/; //18位整数或者17位整数+X正则表达式
				//S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
				if(idType == "B" || idType == "C") {
					if(idType == "B") {
						if(!(re.test(idNo) && (idNo.substring(0,6) == "810000" || idNo.substring(0,6) == "820000"))) {
							myFactory.alert('','港澳居民居住证不合法!','info');
							return;
						}
					}
					if(idType == "C") {
						if(!(re.test(idNo) && idNo.substring(0,6) == "830000")) {
							myFactory.alert('','台湾居民居住证不合法!','info');
							return;
						}
					}
					//判断国籍与证件类型是否相符
					if((idNo.substring(0,6) == "810000" && nativePlace != 'HKG') || 
					   (idNo.substring(0,6) == "820000" && nativePlace != 'MAC') || 
					   (idNo.substring(0,6) == "830000" && nativePlace != 'TWN')) {
						myFactory.alert('','国籍与证件类型不符!','info');
						return;
					}
					//港澳台居民居住证不能选择终身
					if(availDataType == "1") {
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
						myFactory.alert('','港澳台居民居住证不能选择长期','info');
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
						return;
					}
				}
				// add by yinruirong 20180921 添加港澳台证件类型校验 end
				
				/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start*/
				var bnfMobileNew = $("#bnfMobileNew").val();//移动电话1
				var bnfHomePhoneNew = $("#bnfHomePhoneNew").val();//固定电话
				var bnfMobilexNew = $("#bnfMobilexNew").val();//移动电话2
				var bnfAddressNew = $("#bnfAddressNew").val();//通讯地址
				var mobileReg = /^1[0-9]{10}$/;//新需求：1开头，11位数字
				if(bnfMobileNew == null || bnfMobileNew.trim() == ""){
					myFactory.alert("","移动电话1不能为空","info");
					return;
				}else if(!mobileReg.test(bnfMobileNew.trim())){
					myFactory.alert("","移动电话1不正确，请重新确认！","info");
					return;
				}
				if(bnfMobilexNew != null && bnfMobilexNew.trim() != ""){
					if(!mobileReg.test(bnfMobilexNew.trim())){
						myFactory.alert("","移动电话2不正确，请重新确认！","info");
						return;
					}
				}
				if(bnfHomePhoneNew!=null && bnfHomePhoneNew.trim() != ""){
					var telReg01=/^\d{3,4}-?\d{7,9}$/;           //020-34688020
					var telReg02=/^\d{7,11}-?\d{4}?$/;           //34688020-3362
					var telReg03=/^\d{3,4}-?\d{7,9}-?\d{4}?$/;   //020-34688020-3362
					var telReg04=/^\d{7,11}$/;                   //34688020
					if((!telReg01.test(bnfHomePhoneNew.trim()))&&(!telReg02.test(bnfHomePhoneNew.trim()))
							&&(!telReg03.test(bnfHomePhoneNew.trim())&&(!telReg04.test(bnfHomePhoneNew.trim())))) {
						$.alert({title: '',text: '固定电话不正确，请重新确认！',onOK: function () {}});
						return false;
					}
				}
				if (bnfAddressNew!=null && bnfAddressNew.trim() != "" && bnfAddressNew.trim().length<6) {
					$.alert({title: '',text: '地址信息不正确，请重新确认',onOK: function () {}});
					return false;
				}
				/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end*/
		
				/*校验都通过，把符合条件的数据拼装成对象存入item08.benefit*/
				//填装数据中，其中有一些为空是因为，原程序传送后台并没有传送这些数据，而且查看类能知道，在读取数据时候，会根据字段代码去填充这些字段CN
				var item = {
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					"availDataStart" : availDataStart,
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					"availDataClose" : availDataClose,
					"availDataType" : availDataType,
					"availDataTypeCN" : "",
					"benfType" : "D",//固定值，因为页面只有身故受益人
					"benfTypeCN" : "身故受益人",//固定值，因为页面只有身故受益人，唯独这个需要传送
					"birthDay" : birthDay,
					"bnfGrade" : bnfGrade,
					"bnfLot" : bnfLot,
					"genderCN" : "",
					"sex" : sex,
					"idNo" : idNo,
					"idType" : idType,
					"iDTypeCN" : "",
					"name": name,
					"nativePlace" : nativePlace,
					"nativePlaceNm" : nativePlaceNm,
					"relationToInsured" : relationToInsured,
					//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
					//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
					//"idCardBase64Img0" : idCardBase64Img0,
					//"idCardBase64Img1" : idCardBase64Img1,
					//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
					//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
					
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start*/
					"bnfMobile" : bnfMobileNew,
					"bnfHomePhone" : bnfHomePhoneNew,
					"bnfMobilex" : bnfMobilexNew,
					"bnfAddress" : bnfAddressNew,
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end*/
					"relationCN" : ""
				}
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				if ( !$scope.isChangeIdNum0 ){
					item['idCardBase64Img0'] = idCardBase64Img0;
				}//正面
				if ( !$scope.isChangeIdNum1 ) {
					item['idCardBase64Img1'] = idCardBase64Img1;
				};//反面
			//	myFactory.alert('','$scope.isChangeIdNum0 :'+$scope.isChangeIdNum0+"$scope.isChangeIdNum1"+$scope.isChangeIdNum1,"");
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				$scope.item08.benefit.push(item);
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				$scope.isChangeIdNum0 = false;//正面
				$scope.isChangeIdNum1 = false;//反面
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				modal('close','addPeopleModal','overwindowOn08Input','addPeopleModalCloseX');
			}
			
			
			
/*******************************************************新增受益人部分end***************************************************/
			
			
/*******************************************************编辑受益人部分start***************************************************/
			//编辑受益人弹窗 性别单选按钮样式控制
			$scope.editPopSex = function(type){
				if(type==1){
					$scope.EditPopSexFlag = false;
				}else if(type ==2){
					$scope.EditPopSexFlag = true;
				}
				console.log(type);
				console.log($scope.EditPopSexFlag);
			}
			
			//编辑受益人
			$scope.changeBenefit = function(index){
				$.showLoading('正在处理,请稍候');
				setTimeout(function() {
					$.hideLoading();
				}, 300);
				
				console.log(index);
				modal('open','editPeopleModal','overwindowOn08Input','editPeopleModalCloseX');
				/**
				 * 数据加载
				 */
				var item = $scope.item08.benefit[index];//关于这里，只要从数据点击编辑跳过来的，则一定会有数据
//				myFactory.loadingShow();
//				//设置延时触发
//				$timeout(function(){
					$("#benfTypeEdit").val(item.benfType);
					$("#editNo").val(index);//表明当前操作的元素是第几个
					
					$("#nameEdit").val(item.name);
					//加载国籍
					$scope.nativePlaceTextEditSelect = item.nativePlace ;
					$("#nativePlaceTextEditSelect").val(item.nativePlace);
					$scope.changenativePlaceText('Edit');
					//加载证件类型选择
					$scope.idTypeEditSelect = item.idType ; //先给选择框赋值，这种方法赋值不及时，会导致第一次加载失败，但是第二次就能成功,所以应该也写上
					$("#idTypeEditSelect").val(item.idType);//通过这个方式来设置第一次时候的值
					$scope.changeIdType('Edit');//调用函数设置
					//加载证件号码
					$("#idNoEdit").val(item.idNo);
					//加载有限期类型
					$scope.availDataTypeEditSelect = item.availDataType;
					$("#availDataTypeEditSelect").val(item.availDataType);
					$scope.changeAvailDataType('Edit');
					if(item.availDataType=='2'){
						//加载有效截止日
						$("#availDataCloseEdit").val(item.availDataClose);
						myFactory.setDateUtil("availDataCloseEdit",item.availDataClose);
					}

					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					//加载有效起始日
					$("#availDataStartEdit").val(item.availDataStart);
					myFactory.setDateUtil("availDataStartEdit",item.availDataStart);
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					//加载性别
					if(item.sex=="M"){
						$scope.EditPopSexFlag = false;
					}else{
						$scope.EditPopSexFlag = true;
					}
					//初始化出生日期
					$("#birthDayEdit").val(item.birthDay);
					myFactory.setDateUtil("birthDayEdit",item.birthDay);
					//初始化关系
					$scope.relationToInsuredEditSelect = item.relationToInsured;
					$("#relationToInsuredEditSelect").val(item.relationToInsured);
					$scope.changeRelationToInsured('Edit');
					//初始化受益顺序和受益比例
					$("#bnfGradeEdit").val(item.bnfGrade);
					$("#bnfLotEdit").val(item.bnfLot);
					
					$("#bnfLotEdit").val(item.bnfLot);
					
					$("#idCardBase64Img0Edit").val(item.idCardBase64Img0);//身份证正面
					$("#idCardBase64Img1Edit").val(item.idCardBase64Img1);//身份证反面
					
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start*/
					$("#bnfMobileEdit").val(item.bnfMobile);
					$("#bnfHomePhoneEdit").val(item.bnfHomePhone);
					$("#bnfMobilexEdit").val(item.bnfMobilex);
					$("#bnfAddressEdit").val(item.bnfAddress);
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end*/
					
//					myFactory.loadingHide();
//				},2000)
			}
			//编辑受益人关闭弹窗
			$scope.editPeopleCancel = function(){
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				$scope.isChangeIdNum0 = false;//正面
				$scope.isChangeIdNum1 = false;//反面
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				modal('close','editPeopleModal','overwindowOn08Input','editPeopleModalCloseX');
			}
			
			$scope.editPeopleComfirm = function(){
				/**
				 * 获取数据
				 */
				var name = $("#nameEdit").val();//名字
				var nativePlace = $("#nativePlaceEdit").val();//国籍代码
				var nativePlaceNm = $("#nativePlaceNmEdit").val();//国籍名称
				var idType = $("#idTypeEditSelect option:selected").val();//证件类型代码
//				var idTypeCN = $("#idTypeDetailSelect option:selected").text();//证件类型名称
				var idNo = $("#idNoEdit").val();//证件号码
				var availDataType = $("#availDataTypeEditSelect option:selected").val();//有限期类型代码
//				var availDataTypeCN = $("#availDataTypeEditSelect option:selected").text();//有限期类型名称
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				var availDataStart = $("#availDataStartEdit").val();//有效起始日
				//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				var availDataClose = $("#availDataCloseEdit").val();//有效截止日
				var sex;
				if($scope.EditPopSexFlag == false){
					sex = "M";
				}else{
					sex = "F";
				}
				var birthDay = $("#birthDayEdit").val();
				var relationToInsured = $("#relationToInsuredEditSelect option:selected").val();//关系代码
//				var relationToInsuredCN = $("#relationToInsuredEditSelect option:selected").text();//关系名称
				var bnfGrade = $("#bnfGradeEdit").val();//受益顺序
				var bnfLot = $("#bnfLotEdit").val();//受益比例
				
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
				var idCardBase64Img0 = $("#idCardBase64Img0Edit").val();//身份证正面
				var idCardBase64Img1 = $("#idCardBase64Img1Edit").val();//身份证反面
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
				
				/**
				 * 数据校验
				 */
				if(systemDate==null || systemDate == undefined || systemDate =="" ){
					myFactory.alert("","系统发生错误，请返回重试","info");
					return;
				}
				if(name == null || name.trim() == "" ){
					myFactory.alert("","名字不能为空","info");
					return;
				}
				
				if(nativePlace == null || nativePlace.trim() == "" || nativePlace == undefined){
					myFactory.alert("","请选择国籍","info");
					return;
				}
				
				if(idNo == null || idNo.trim() == ""){
					myFactory.alert("","证件号码不能为空","info");
					return;
				}
				
				//证件号码校验
				if(idType =='1' || idType =='7' ){
					var checkStr = checkCard(idNo);
					//先执行对证件号码的校验，如果没有错再进入下一步设置出声日期以及性别
					if(checkStr!=""){
						myFactory.alert("",checkStr,"info");
						return;
					}
				}
				
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(idType =='A'){
					if(!checkCardToA(idNo.trim(),birthDay.trim(),sex)){
						myFactory.alert("","证件号码不正确，请重新确认","info");
						return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
				if(idType =='A' && availDataType==1){
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 start
					myFactory.alert("","外国人永久居留身份证有效期类型不可选择长期","info");
					//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231114 end
					/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
					return;
				}
				
				//当证件有效类型不是终身时执行校验
				if(availDataType!=1){
					if(availDataClose == null || availDataClose.trim() == ""){
						myFactory.alert("","有效截止日不能为空","info");
						return;
					}
					//证件有效期必须大于当前日期
				    if(availDataClose <= systemDate ){  	//需要注意的是，systemDate找不到定义所在
				    	myFactory.alert("","证件有效截止日必须大于当前日期，请重新确认","info");
				    	return;
				    }
				  //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					if(availDataStart == null || availDataStart.trim() == ""){
						myFactory.alert("","有效起始日不能为空","info");
						return;
					}
					
				    if($.trim(availDataStart)<birthDay){ 
						prompt="有效期起始日必须大于出生日期，请确认后填写！";
						myFactory.alert('','有效期起始日必须大于出生日期，请确认后填写！','info');
						return false;
					}
				    if($("#idTypeEditInput").val() =="身份证"){
						if($.trim(availDataStart)<'2004-03-29'){
							prompt="有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！";
							myFactory.alert('','有效期起始日必须大于等于2004年3月29日（二代身份证启用日），请确认后填写！','info');
							return false;
						}
				    }
					if($.trim(availDataStart)>systemDate){
						
						prompt="有效期起始日必须少于等于当前日，请确认后填写！";
						myFactory.alert('','有效期起始日必须少于等于当前日，请确认后填写！','info');
						return false;
					}
				  //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
				}
				
				//出生日校验
				if(birthDay == null || birthDay.trim() == ""){
					myFactory.alert("","出生日期不能为空","info");
					return;
				}else{
					if( birthDay >= systemDate ){
						myFactory.alert("","出生日期不能大于当前日期，请重新确认","info");
				    	return;
				    }
				}
				
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 start
				if(idType =='A'){
					if(!changeAvailDataStart(availDataStart,availDataClose,birthDay)){
						myFactory.alert("","您填写的证件有效期不正确，请按证件上的实际有效日期填写！","info");
				    	return;
					}
				}
				//S2023103127804-粤金办发〔2023〕27号-外国人永久居留身份证规则调整系统需求 add by huanghk 20231103 end
				
				//证件类型为身份证时，45岁（含）以下证件有效期不可为终身
	   	   		if(idType == '1'){
	   	   			if(availDataType == '1'){
	   	   				var iDate=birthDay;//出生日期
						var age = getAge(iDate);
						if(age<=45){
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
							myFactory.alert("","45岁（含）以下有效期类型不可为长期，请重新确认","info");
							/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
   	   						return;
						}
	   	   			}
	   	   		}
				
				if(bnfGrade == null || bnfGrade.trim() == ""){
					myFactory.alert("","受益顺序不能为空","info");
					return;
				}
				if(bnfLot == null || bnfLot.trim() == ""){
					myFactory.alert("","比率不能为空","info");
					return;
				}
    	   		
				//重复校验身份证号码和性别、出生日期是否对应
				if(idType =='1' || idType =='7' ){
					var strReturn = checkDateOrSex("Edit",$scope.EditPopSexFlag);
					if(strReturn == false){
						return;    //如果返回false,说明校验失败
					}
				}
				
				// add by yinruirong 20180921 添加港澳台证件类型校验 start
				/**************************
				 * 1.证件类型为港澳台居民居住证(810000或820000或830000开头的18位数)，国籍只能选"中国-香港"、"中国-澳门"、"中国台湾"
				 * 2.证件有效期类型不能选择终身
				 * 3.证件有效期不能为空
				 */
				var re = /^\d{18}$/; //18位整数正则表达式
				if(idType == "B" || idType == "C") {
					if(idType == "B") {
						if(!(re.test(idNo) && (idNo.substring(0,6) == "810000" || idNo.substring(0,6) == "820000"))) {
							myFactory.alert('','港澳居民居住证不合法!','info');
							return;
						}
					}
					if(idType == "C") {
						if(!(re.test(idNo) && idNo.substring(0,6) == "830000")) {
							myFactory.alert('','台湾居民居住证不合法!','info');
							return;
						}
					}
					//判断国籍与证件类型是否相符
					if((idNo.substring(0,6) == "810000" && nativePlace != 'HKG') || 
					   (idNo.substring(0,6) == "820000" && nativePlace != 'MAC') || 
					   (idNo.substring(0,6) == "830000" && nativePlace != 'TWN')) {
						myFactory.alert('','国籍与证件类型不符!','info');
						return;
					}
					//港澳台居民居住证不能选择终身
					if(availDataType == "1") {
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
						myFactory.alert('','港澳台居民居住证不能选择长期','info');
						/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
						return;
					}
				}
				// add by yinruirong 20180921 添加港澳台证件类型校验 end
				
				//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start
				var bnfMobileEdit = $("#bnfMobileEdit").val();//受益人手机号码1
				var bnfHomePhoneEdit = $("#bnfHomePhoneEdit").val();//固定电话
				var bnfMobilexEdit = $("#bnfMobilexEdit").val();//手机号码2
				var bnfAddressEdit = $("#bnfAddressEdit").val();//通讯地址
				var mobileReg = /^1[0-9]{10}$/;//新需求：1开头，11位数字
				if(bnfMobileEdit == null || bnfMobileEdit.trim() == ""){
					myFactory.alert("","移动电话1不能为空","info");
					return;
				}else if(!mobileReg.test(bnfMobileEdit.trim())){
					myFactory.alert("","移动电话1不正确，请重新确认！","info");
					return;
				}
				if(bnfMobilexEdit != null && bnfMobilexEdit.trim() != ""){
					if(!mobileReg.test(bnfMobilexEdit.trim())){
						myFactory.alert("","移动电话2不正确，请重新确认！","info");
						return;
					}
				}
				if(bnfHomePhoneEdit!=null && bnfHomePhoneEdit.trim() != ""){
					var telReg01=/^\d{3,4}-?\d{7,9}$/;           //020-34688020
					var telReg02=/^\d{7,11}-?\d{4}?$/;           //34688020-3362
					var telReg03=/^\d{3,4}-?\d{7,9}-?\d{4}?$/;   //020-34688020-3362
					var telReg04=/^\d{7,11}$/;                   //34688020
					if((!telReg01.test(bnfHomePhoneEdit.trim()))&&(!telReg02.test(bnfHomePhoneEdit.trim()))
							&&(!telReg03.test(bnfHomePhoneEdit.trim())&&(!telReg04.test(bnfHomePhoneEdit.trim())))) {
						$.alert({title: '',text: '固定电话不正确，请重新确认！',onOK: function () {}});
						return false;
					}
				}
				if (bnfAddressEdit!=null && bnfAddressEdit != "" && bnfAddressEdit.trim().length<6) {
					$.alert({title: '',text: '地址信息不正确，请重新确认',onOK: function () {}});
					return false;
				}
				//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end
				
				/*校验都通过，把符合条件的数据拼装成对象存入item08.benefit*/
				//填装数据中，其中有一些为空是因为，原程序传送后台并没有传送这些数据，而且查看类能知道，在读取数据时候，会根据字段代码去填充这些字段CN
				var item = {
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
				    "availDataStart" : availDataStart, 
				    //S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					"availDataClose" : availDataClose,
					"availDataType" : availDataType,
					"availDataTypeCN" : "",
					"benfType" : "D",//固定值，因为页面只有身故受益人
					"benfTypeCN" : "身故受益人",//固定值，因为页面只有身故受益人，唯独这个需要传送
					"birthDay" : birthDay,
					"bnfGrade" : bnfGrade,
					"bnfLot" : bnfLot,
					"genderCN" : "",
					"sex" : sex,
					"idNo" : idNo,
					"idType" : idType,
					"iDTypeCN" : "",
					"name": name,
					"nativePlace" : nativePlace,
					"nativePlaceNm" : nativePlaceNm,
					"relationToInsured" : relationToInsured,
					//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
					//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
//					"idCardBase64Img0" : idCardBase64Img0,
//					"idCardBase64Img1" : idCardBase64Img1,
					//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
					//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
					
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start*/
					"bnfMobile" : bnfMobileEdit,
					"bnfHomePhone" : bnfHomePhoneEdit,
					"bnfMobilex" : bnfMobilexEdit,
					"bnfAddress" : bnfAddressEdit,
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end*/
					
					"relationCN" : ""
				}
				var index = $("#editNo").val();//得到当前操作的元素是第几个
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				if ( !$scope.isChangeIdNum0 ){
					item['idCardBase64Img0'] = idCardBase64Img0;
				}//正面
				if ( !$scope.isChangeIdNum1 ) {
					item['idCardBase64Img1'] = idCardBase64Img1;
				};//反面
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				$scope.item08.benefit[index] = item; //将所操作的对象数据进行调整
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 start
				$scope.isChangeIdNum0 = false;//正面
				$scope.isChangeIdNum1 = false;//反面
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190423 end
				modal('close','editPeopleModal','overwindowOn08Input','editPeopleModalCloseX');//关闭弹框
			}
			
/*******************************************************编辑受益人部分start***************************************************/
			
			
			
			//删除受益人
			$scope.deletePeople = function(){
//				$($event).parent('.trClassTest').remove();
				var afterDetele = [];
				$("#addPeople tbody tr").each(function(index,el){//index为数据条数，从0开始，el代表整行
					if($(el).find("input.weui-check").prop("checked") == true){
						//$(el).remove();//页面移除该行,不使用该行，会出现JQ跟anglar冲突的问题，采用让repeat标签自动根据item08.benefit更新就行了
						$scope.item08.benefit[index]="";//置空对应index函数
					}
				});
				
				for(var i=0 ;i<$scope.item08.benefit.length ; i++){
					if($scope.item08.benefit[i]!=""){
						afterDetele.push($scope.item08.benefit[i]);//如果不为空，放入处理后数组
					}
				}
				$scope.item08.benefit = afterDetele;//最后将数组替换item08.benefit即可，最后数据提交也提交这个即可
//				console.log($scope.item08.benefit);
			}
			
			
			/**
			 * 扫描身份证信息
			 */
			$scope.scanIDCardInfoItem08 = function (type) {
				if($scope.isPhotoOCRFlag){
					$scope.isPhotoOCRFlag=false;
					setTimeout(function() {
						$scope.isPhotoOCRFlag=true;
					}, 350);
				}else{
					return false;
				}
				//移动端
				cordova.sino.getIDCardInfo(function(result){
					if(result.success){
						if(!result.data.exit){
							if(appVersion==="IOS"){
								if(result.data.ok){
									if(result.data.isFront){
										//身份证正面
										var name=result.data.Name;
										var birthday=result.data.Birthday;
										var id =result.data.Id;//证件号码
										var address=result.data.Address;
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
										var idCardSmallPic=result.data.smallPic;
										var idCardBigPic=result.data.bigPic;
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
										//alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据

										$("#name"+type).val(name);//填充姓名
										//初始化证件选择，选择为身份证
										$scope["idType"+type+"Select"] = "1"; //先给选择框赋值，这种方法赋值不及时，会导致第一次加载失败，但是第二次就能成功,所以应该也写上
										$("#idType"+type+"Select").val("1");//通过这个方式来设置第一次时候的值
										$("#idType"+type+"Input").val("身份证");
										//强行让国籍为中国，并且变为不可改变
										//加载国籍
										$scope["nativePlaceText"+type+"Select"] = "CHN";//选择国籍为中国
										$("#nativePlaceText"+type+"Select").val("CHN");
										$scope.changenativePlaceText(type);
										$("#nativePlaceText"+type+"Select").attr("disabled",true); //禁止二次选择
										//加载证件号码
										$("#idNo"+type).val(id);
										//在这里想办法让证件号码聚焦再失焦，这样会自动更新性别
										$("#idNo"+type).focus();
										//初始化出生日期
										$("#birthDay"+type).val(birthday);
										myFactory.setDateUtil("birthDay"+type,birthday);
										$("#name"+type).focus();//焦点重新定位即可
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
										$("#idCardBase64Img0"+type).val(idCardBigPic);
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
									}else{
										//身份证反面
										var validity=result.data.Validity;//有效期
										//alert(Validity);
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
										var idCardSmallPic=result.data.smallPic;
										var idCardBigPic=result.data.bigPic;
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
										var oldValidity=result.data.OldValidity;//有效期
										//存在有效期为长期的情况：
										if(validity=='长期' || validity=='终身'){
											//加载有限期类型
											$scope["availDataType"+type+"Select"] = "1";//身份证默认有限年期
											$("#availDataType"+type+"Select").val("1");
											/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
											$("#availDataType"+type+"Input").val("长期");
											/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
											
											$("#availDataClose"+type).val(" ");//置空有效期截止日，多一个空格，使不显示灰色提醒
											$("#availDataClose"+type).attr("disabled",true);
											$scope.changeAvailDataType(type);

											$("#availDataStart"+type).val(oldValidity);
											myFactory.setDateUtil("availDataStart"+type,oldValidity);
										}else{
											//加载有限期类型
											$scope["availDataType"+type+"Select"] = "2";//身份证默认有限年期
											$("#availDataType"+type+"Select").val("2");
											$("#availDataType"+type+"Input").val("年期");
											$("#availDataStart"+type).attr("disabled",false);
											$("#availDataClose"+type).attr("disabled",false);
											$scope.changeAvailDataType(type);
											$("#availDataStart"+type).val(oldValidity);//置空有效期起始日，多一个空格，使不显示灰色提醒
											myFactory.setDateUtil("availDataStart"+type,oldValidity); 
											//加载有效截止日
											$("#availDataClose"+type).val(validity);
											myFactory.setDateUtil("availDataClose"+type,validity);
										}
										//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
										$("#idCardBase64Img1"+type).val(idCardBigPic);
										//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
									}
								}
							}else{
								$scope.smallPic=result.data.smallPic;
					            $scope.bigPic=result.data.bigPic;
					            result.data.smallPic="";
								result.data.bigPic="";
								cordova.sino.confirmIDCardInfo(function(result){
									if(result.success){
										if(result.data.ok){
											if(result.data.isFront){
												//身份证正面
												var name=result.data.Name;
												var birthday=result.data.Birthday;
												var id =result.data.Id;//证件号码
												var address=result.data.Address;
												//alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据

												$("#name"+type).val(name);//填充姓名
												//初始化证件选择，选择为身份证
												$scope["idType"+type+"Select"] = "1"; //先给选择框赋值，这种方法赋值不及时，会导致第一次加载失败，但是第二次就能成功,所以应该也写上
												$("#idType"+type+"Select").val("1");//通过这个方式来设置第一次时候的值
												$("#idType"+type+"Input").val("身份证");
												//强行让国籍为中国，并且变为不可改变
												//加载国籍
												$scope["nativePlaceText"+type+"Select"] = "CHN";//选择国籍为中国
												$("#nativePlaceText"+type+"Select").val("CHN");
												$scope.changenativePlaceText(type);
												$("#nativePlaceText"+type+"Select").attr("disabled",true); //禁止二次选择
												//加载证件号码
												$("#idNo"+type).val(id);
												//在这里想办法让证件号码聚焦再失焦，这样会自动更新性别
												$("#idNo"+type).focus();
												//初始化出生日期
												$("#birthDay"+type).val(birthday);
												myFactory.setDateUtil("birthDay"+type,birthday);
												$("#name"+type).focus();//焦点重新定位即可
												
												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
												$("#idCardBase64Img0"+type).val($scope.bigPic);
												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
											}else{
												//身份证反面
												var validity=result.data.Validity;//有效期
												//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
												var oldValidity=result.data.OldValidity;//有效期
												//存在有效期为长期的情况：
												if(validity=='长期' || validity=='终身'){
													//加载有限期类型
													$scope["availDataType"+type+"Select"] = "1";//身份证默认有限年期
													$("#availDataType"+type+"Select").val("1");
													/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 start*/
													$("#availDataType"+type+"Input").val("长期");
													/*S2020120315839_增加记录证件有效期起始日  add by huanghaokun 20210719 end*/
													$("#availDataClose"+type).val(" ");//置空有效期截止日，多一个空格，使不显示灰色提醒
													$("#availDataClose"+type).attr("disabled",true);
													$scope.changeAvailDataType(type);

													$("#availDataStart"+type).val(oldValidity);
													myFactory.setDateUtil("availDataStart"+type,oldValidity);
												}else{
													//加载有限期类型
													$scope["availDataType"+type+"Select"] = "2";//身份证默认有限年期
													$("#availDataType"+type+"Select").val("2");
													$("#availDataType"+type+"Input").val("年期");
                                                    $("#availDataStart"+type).attr("disabled",false);
													$("#availDataClose"+type).attr("disabled",false);
													$scope.changeAvailDataType(type);
													
													$("#availDataStart"+type).val(oldValidity);
													myFactory.setDateUtil("availDataStart"+type,oldValidity);
													//加载有效截止日
													$("#availDataClose"+type).val(validity);
													myFactory.setDateUtil("availDataClose"+type,validity);
												}
												//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end

												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
												$("#idCardBase64Img1"+type).val($scope.bigPic);
												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
												//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
											}
										}
									}
								},result.data);
							}
						}
					}
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190414 start
				});
				//S2019012807164 - 信易通OCR识别功能 add by csf 20190414 end
				//PC端开发测试用
				/*var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
				var result = {
					data : {
						Name:"张三",
						Birthday:"2015-03-23",
						//Id:"440771201503231715",
						Id:"445121199404273924",
						Address:"广东省广州市天河区某街道23号",
						Validity:"2050-08-23",
						smallPic:testVal,
						bigPic:testVal,
						ok:"true",
						isFront:"true"//正面
						//isFront:"false"//反面
					}
				};

				if(result.data.ok){
					//*********************************待开发逻辑代码区域begin**********************************
					if(result.data.isFront){
						//身份证正面
						var name=result.data.Name;
						var birthday=result.data.Birthday;
						var id =result.data.Id;//证件号码
						var address=result.data.Address;
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
						var idCardSmallPic=result.data.smallPic;
						var idCardBigPic=result.data.bigPic;
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
						//alert(name+","+Birthday+","+id+","+Address); //扫描获得的数据
						
						$("#name"+type).val(name);//填充姓名
						//初始化证件选择，选择为身份证
						$scope["idType"+type+"Select"] = "1"; //先给选择框赋值，这种方法赋值不及时，会导致第一次加载失败，但是第二次就能成功,所以应该也写上
						$("#idType"+type+"Select").val("1");//通过这个方式来设置第一次时候的值
						$("#idType"+type+"Input").val("身份证");
						//强行让国籍为中国，并且变为不可改变
						//加载国籍
						$scope["nativePlaceText"+type+"Select"] = "CHN";//选择国籍为中国
						$("#nativePlaceTextEditSelect").val("CHN");
						$scope.changenativePlaceText(type);
						$("#nativePlaceText"+type+"Select").attr("disabled",true); //禁止二次选择
						//加载证件号码
						$("#idNo"+type).val(id);
						$("#idNo"+type).focus();
						//初始化出生日期
						$("#birthDay"+type).val(birthday);
						$("#name"+type).focus();//焦点重新定位即可
						
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
						$("#idCardBase64Img0"+type).val(idCardBigPic);
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
					}else{
						//身份证反面
						var validity=result.data.Validity;//有效期
						//alert(Validity);
						
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
						var idCardSmallPic=result.data.smallPic;
						var idCardBigPic=result.data.bigPic;
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
						
						//加载有限期类型
						$scope["availDataType"+type+"Select"] = "2";//身份证默认有限年期
						$("#availDataType"+type+"Select").val("2");
						$("#availDataType"+type+"Input").val("年期");
						$scope.changeAvailDataType(type);
						//加载有效截止日
						$("#availDataClose"+type).val(validity);
						
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
						$("#idCardBase64Img1"+type).val(idCardBigPic);
						//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
					}
					//*********************************待开发逻辑代码区域end**********************************
				}*/
				
			}//扫描身份证信息END
	
			/**
			 * 扫描身份证反面信息
			 */
			$scope.scanBackIDCardInfoItem08 = function (type,flag) {
				$.confirm("请扫描身份证反面", "", function() {
					$scope.scanIDCardInfoItem08(type,flag);
				});
			}
			//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
			$scope.jpgopen = function(){ 
				$state.go('jpgopen', {
                    itemId: itemId,
                    chdrnum01: chdrnum01,
                    chdrcoy: chdrcoy
                });
			}
			//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
			//下一步
			$scope.nextStep = function(){
				//判断是否初始化完成了，如果失败，不予进入下一步
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return;
				}
				
				/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 start*/
				//检测查阅弹框
		        var readImageFlag = $("#readImageFlag").val();
	    		if(readImageFlag=="false"){
	    			//S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 start
	    			myFactory.alert('',"请阅读《投保人和被保险人声明与授权事项》和《中信保诚隐私政策》！",'info');
	    			//S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 end
	    			return;
	    		}	
	    		/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 end*/
				
				if($scope.item08.benefit.length == 0 ){
					//myFactory.alert("","至少应该有一位受益人!","info");
					myFactory.alert("","未输入受益人信息!","info");
					return;
				}
				
				//计算各受益顺序比例是否满足100
				var sx = $scope.item08.benefit;//用于存放总共有多少行受益人信息，其实也就是item08.benefit
		    	var sxarray = new Array();//用于存放不重复的受益顺序
				//获取不重复的受益顺序
				for(var i = 0;i<sx.length;i++){//获取不重复的受益顺序，对每一行受益人信息进行判断
		    		var ifhas=false;
		    		for(var j =0; j<sxarray.length; j++){
		    			if(sxarray[j]==sx[i].bnfGrade){ //如果集合中已经存在有相同的受益顺序
		    				ifhas=true;
		    			}
		    		}
		    		if(!ifhas){
		    		   sxarray[sxarray.length]=sx[i].bnfGrade; //如果集合中不存在有相同的受益顺序，则加到集合中
		    		}
		    	} 
				for(var q=0;q<sxarray.length;q++){    //对每一个收益顺序单独校验，比如同样是顺序为1的一起校验，一样是2的一起校验
		    	   	var sxObj = $scope.item08.benefit; 
		    	   	var talRate=0;
		    	   	var errorFiled;
		    	   	for(var f=0;f<sxObj.length;f++){  //对每一条受益人信息进行循环
		    	   		if(sxObj[f].bnfGrade!=sxarray[q]){  //如果受益人收益顺序跟当前想要大体操作的收益顺序不同，则跳过不做这次操作
		    	   			continue;
		    	   		}
		    	   		var rate = sxObj[f].bnfLot  //找到受益比例的值
		    	   		talRate+=parseInt(rate);  //转化得到受益比例数字，并叠加到talRate里面
		    	   	}
		    	    if(talRate!=100){
		    	    	//myFactory.alert("","受益顺序"+sxarray[q]+"的总比例应该等于100！","info");
		    	    	myFactory.alert("","受益顺序"+sxarray[q]+"的受益总比例不为100%！","info");
		    	        return;
		    	    }
		    	}
				//有效截止日期trim处理
				var pageBenefit = $scope.item08.benefit
				for(var t=0;t<pageBenefit.length;t++){ 
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 start
					pageBenefit[t].availDataStart = pageBenefit[t].availDataStart.trim();
					//S2020120315839_增加记录证件有效期起始日  add by mqz 20210125 end
					pageBenefit[t].availDataClose = pageBenefit[t].availDataClose.trim();
				}
				
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 begin
				//存储证件类型为身份证，使用了OCR扫描证件信息到缓存中
				//name-picVal
				var benefiIdCardData=[];
				var isUserOcrFlag=false;
				for(var t=0;t<pageBenefit.length;t++){ 
					var idType = pageBenefit[t].idType;
					if("1"==idType){//证件类型为身份证
						var bfName = pageBenefit[t].name;
						var idCardBase64Img0 = pageBenefit[t].idCardBase64Img0;
						var idCardBase64Img1 = pageBenefit[t].idCardBase64Img1;
						//扫描了正面或者反面
						if((""!=idCardBase64Img0 && null!=idCardBase64Img0 && undefined!=idCardBase64Img0)||(""!=idCardBase64Img1 && null!=idCardBase64Img1 && undefined!=idCardBase64Img1)){
							var idCardParam={"itemId":"08","chdrnum":chdrnum01,"role":"bf","bfName":bfName,"idCardBase64Img0":idCardBase64Img0,"idCardBase64Img1":idCardBase64Img1};
							benefiIdCardData.push(idCardParam);
							if(!isUserOcrFlag){
								isUserOcrFlag=true;
							}
							pageBenefit[t].idCardBase64Img0 = "";//置空
							pageBenefit[t].idCardBase64Img1 = "";//置空
						}
					}
				}
				if(isUserOcrFlag){//使用了OCR扫描证件，则保存证件图片信息
					$scope.saveIdCardCache(benefiIdCardData);
				}
				//S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711 end
				
				//一切数据校验完毕，进行数据封装
				var pageData = {
					"itemId":itemId,
					"benefit": pageBenefit
				}
				
				//跳转check_main
			    $ionicHistory.clearCache().then(function(){ 
					$state.go('content_check_main',{
						itemId:itemId,
						item:pageData,
						chdrnum01:chdrnum01,
						chdrcoy:chdrcoy,
						searchParam:searchParam
					});
				})
			}
			
			/**
			 * S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180711
			 * OCR证件扫描证件信息缓存
			 */
			$scope.saveIdCardCache = function(idCardParam){
				var idCardItems={"idCardItems":idCardParam};
				var token=sessionStorage.getItem("token");
				var timestamp=myFactory.getTimetamp();
				var sfis= "token-timestamp";
				var signStr="token="+token+"&timestamp="+timestamp;
				var sign = myFactory.hex(signStr);
				$http({
					method: 'POST',
					url: app.domain + 'img/saveIdCard08Cache.action',
					data:{paramsMap:idCardItems,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						console.log("saveIdCardCache ok");
					}
				}, function errorCallback(response) {
					console.log("saveIdCardCache error");
				});
			}
			
			/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 start*/
			//客户须知弹框
			$scope.tipOpen = function(){
				modal('open','tip_model','policyWindowOn08Input');
			}
			$scope.tipClose = function(){
				modal('close','tip_model','policyWindowOn08Input');
			}
			//页面同意阅读协议复选框部分
			$scope.changeReadFlag = function(){
				$scope.readFlag = !$scope.readFlag;
			}
			/*S2019070309187 - 电子保全增加个人信息授权内容需求 add by yangyan 20190717 end*/
			
			//S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 start
			$scope.privacyOpen = function(){ 
				$state.go('privacy', {
                    itemId: itemId,
                    chdrnum01: chdrnum01,
                    chdrcoy: chdrcoy
                });
			}
			//S2020050812880-个人信息安全项目-修改变更项目录入页面的个人信息授权内容需求 add by yangyan 20200615 end 
			
			//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 start
			//省市区级联下拉列表
			var regionDataTemp="";
			var citysTemp="";
			var districtsTemp="";
			var unshow_provinces_a = ["北京市", "上海市", "重庆市", "天津市"];
			var unshow_provinces_b = ["台湾省", "香港特别行政区", "澳门特别行政区"];
			var flag = false;
			var proType = 0;//0-普通，1-直辖市，2-特别行政区

			$scope.regionData = [];
			$scope.citys = [];
			$scope.districts = [];
			$scope.regionText = {};
			$scope.$watch('selectedProvince',function(newValue,oldValue){
				//debugger;
				console.log(newValue,oldValue);
				if(newValue != oldValue){
					$("#proChangeFlagHId").val("1");//地址省级行政区发生变化CRS需校验区域变化
					if(!newValue){ //判断选择的是否选择省份，如果没有则重置市区
						$scope.citys = [];
						$scope.districts = [];
						return;
					}
					getAreas("city", newValue);
					$scope.districts = [];
				}
			});

			$scope.$watch('selectedCity',function(newValue,oldValue){
				//debugger;
				if(newValue != oldValue){
					if(!newValue){ //作用同上
						$scope.districts = [];
						return;
					}
					getAreas("district", newValue);
				}
			});
			$scope.districtObj = {};
			$scope.$watch('selectedDstrict',function(newValue,oldValue){
				if(newValue != oldValue){
					var i = 0; len = $scope.districts.length;
					for(i;i < len ; i ++){
						if($scope.districts[i].id == $scope.selectedDstrict){
							$scope.districtObj = $scope.districts[i];
							$scope.regionText.selectedDstrictText = $scope.districts[i].text;
							console.log('区名',$scope.regionText.selectedDstrictText);
						}
					}
				}
			});
			
			//弹出弹窗
			$scope.chooseAttr = function(type){
				var address;
				if(type=="new"){
					address = $("#bnfAddressNew").val();
					$scope.openwindow = "new";
				}else{
					address = $("#bnfAddressEdit").val();
					$scope.openwindow = "edit";
				}
				
				modal('open','addrModal','addrWindow','addrCloseX');
				if (!flag) {
					clearAddress();
					initAddr(address);
				}
			}
			
			function clearAddress() {
				$("#town").val("");
				$("#country").val("");
				$("#address_a").val("");
			}

			function initAddr(address) {
				flag = true;
				var promise = getAreas("province", "0");
				promise.then(function success(returnData) {//成功回调
					var prov = getProvFromAddr(address);//获取省份
					if (prov != null) {
						//获取城市
						var promiseCity = getAreas("city", prov.dutycode);
						promiseCity.then(function success(returnCity) {//成功回调
							address = address.substring(prov.dutyname.length);
							if (prov.type == 0) {
								var city = getCityFromAddr(prov.dutycode, address);//获取城市
								if (city != null) {
									$("#address_a").val(address);
									var promiseDistrict = getAreas("district", city.dutycode);
									promiseDistrict.then(function success(returnDistrict) {//成功回调
										address = address.substring(city.dutyname.length);
										var district = getDistrictFromAddr(city.dutycode, address);
										if (district != null) {
											address = address.substring(district.dutyname.length);
											$("#address_a").val(address);
										}
									},function error(errDistrict) {//错误回调
										console.log(errDistrict);
										alert("获取区异常");
									});
								}
							} else if (prov.type == 1) {
								var cityTemp2=$scope.citys;
								$scope.selectedCity=$scope.citys[0].dutycode;
								var promiseDistrict = getAreas("district", $scope.citys[0].dutycode);
								promiseDistrict.then(function success(returnDistrict) {//成功回调
									var district = getDistrictFromAddr($scope.citys[0].dutycode, address);
									if (district != null) {
										address = address.substring(district.dutyname.length);
										$("#address_a").val(address);
									}
								},function error(errDistrict) {//错误回调
									alert("获取区异常");
								});
							} else if (prov.type == 2) {
								$scope.selectedCity=$scope.citys[0].dutycode;
								var promiseDistrict = getAreas("district", $scope.citys[0].dutycode);
								     promiseDistrict.then(function success(returnDistrict) {//成功回调
								     var districtTemp2=$scope.districts;
									 $scope.selectedDstrict=$scope.districts[0].dutycode;
								 },function error(errDistrict) {//错误回调
								     alert("获取区异常");
								 });
							}
						},function error(errCity) {//错误回调
							console.log(errCity);
							alert("获取城市异常");
						});
					}

					$("#address_a").val(address);
				},function error(err) {//错误回调
					console.log(err);
					alert("获取省份异常");
				});
			}
			
			function getAreas(objId, pId) {
				var token=sessionStorage.getItem("token");
				var timestamp=myFactory.getTimetamp();
				var sfis= "pId-token-timestamp";
				var signStr="pId="+pId+"&token="+token+"&timestamp="+timestamp;
				var sign = myFactory.hex(signStr);
				var deferred = $q.defer();//声明承诺
				$http({
					method: 'GET',
					url: app.domain + 'common/getAreas.action',
					params: {'pId': pId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					var tmpData = eval(response.data);
					if (tmpData.length > 0) {
						if (objId == "province") {
							$scope.regionData=tmpData;
						}else if(objId == "city"){
							$scope.citys=tmpData;
						}else if(objId == "district"){
							$scope.districts=tmpData;
						}
					}else{
						if(objId == "district"){
							$scope.districts="";
						}
					}
					deferred.resolve(response);//请求成功
				}, function errorCallback(response) {
					alert('查询数据失败!');
				});
				return deferred.promise;//返回承诺
			}

            //获取地址省份
			function getProvFromAddr(address) {
				var province = null;
				var provinceTemp = null;
				var prov = "";
				var type = 0;//0-普通，1-直辖市，2-特别行政区
				for (var i = 0; i < unshow_provinces_a.length; i++) {
					if (address.indexOf(unshow_provinces_a[i]) == 0) {
						prov = unshow_provinces_a[i];
						type = 1;
						break;
					}
				}
				for (var i = 0; i < unshow_provinces_b.length; i++) {
					if (address.indexOf(unshow_provinces_b[i]) == 0) {
						prov = unshow_provinces_b[i];
						type = 2;
						break;
					}
				}
				if (prov == "") {
					if (address.indexOf("省") > 0) {
						prov = address.substr(0, address.indexOf("省") + 1);
					} else if (address.indexOf("自治区") > 0) {
						prov = address.substr(0, address.indexOf("自治区") + 3);
					}
				}
				if (prov != "") {
					provinceTemp=$scope.regionData;
					var i = 0;len = provinceTemp.length;
					for(i;i < len;i ++){
						if(provinceTemp[i].dutyname == prov){
							console.log('省名:'+prov+"provinceTemp[i].dutycode:"+provinceTemp[i].dutycode);
							$scope.selectedProvince=provinceTemp[i].dutycode;
							province = {"dutycode":provinceTemp[i].dutycode, "dutyname":provinceTemp[i].dutyname}
							break;
						}
					}
				}
				if (province != null) {
					province.type = type;
				}
				return province;
			}

            //获取城市
			function getCityFromAddr(pId, address) {
				var city = null;
				var cityTemp=$scope.citys;
				var i = 0;len = cityTemp.length;
				for(i;i < len;i ++){
					if(address.indexOf(cityTemp[i].dutyname) == 0){
						$scope.selectedCity=cityTemp[i].dutycode;
						city = {"dutycode":cityTemp[i].dutycode, "dutyname":cityTemp[i].dutyname}
					}
				}
				return city;
			}

			//获取地区
			function getDistrictFromAddr(pId, address) {
				var district = null;
				var districtTemp=$scope.districts;
				var i = 0;len = districtTemp.length;
				for(i;i < len;i ++){
					if(address.indexOf(districtTemp[i].dutyname) == 0){
						$scope.selectedDstrict=districtTemp[i].dutycode;
						district = {"dutycode":districtTemp[i].dutycode, "dutyname":districtTemp[i].dutyname}
					}
				}
				return district;
			}

			$scope.adCancel = function(){
				modal('close','addrModal','addrWindow','addrCloseX');
				if (!flag) {
					clearAddress();
				}
			}
			
			//确定关闭弹窗
			$scope.certainClose = function(){
				var province = $("#province").find("option:selected").text();
				if (province == "请选择") {
					$.alert({title: '',text: '省/自治区必填！',onOK: function () {}});
					return;
				}
				var city = $("#city").find("option:selected").text();
				if (city == "请选择") {
					$.alert({title: '',text: '市必填',onOK: function () {}});
					return;
				}
				var district = $("#district").find("option:selected").text();
				var districtOptions = $("#district option");
				if (districtOptions.length > 1) {
					if (district == "请选择") {
						$.alert({title: '',text: '区/县必填',onOK: function () {}});
						return;
					}
				} else {
					district = "";
				}

				var town = $("#town").val();
				var country = $("#country").val();
				var address_a = $("#address_a").val();
				if (address_a == "") {
					$.alert({title: '',text: '详细地址必填',onOK: function () {}});
					return;
				}
				if($scope.openwindow=="new"){
					$("#bnfAddressNew").val(province + city + district + town + country + address_a);
				}else{
					$("#bnfAddressEdit").val(province + city + district + town + country + address_a);
				}
				modal('close','addrModal','addrWindow','addrCloseX');
			}
			//S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220316 end
		}]);     
	
		//指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});
})(app)